<?php

class Template {

    public $context = [];

    /**
     * @var Twig_Environment 
     */
    private $twig;

    public function __construct(Exception $exception = NULL) {
        if (isset($exception)) {
            $this->context['exception'] = $exception;
        }
        require_once 'app/lib/Twig/Autoloader.php';
        Twig_Autoloader::register();
        $loader = new Twig_Loader_Filesystem('app/templates');
        $this->twig = new Twig_Environment($loader);
    }

    public function display($name) {
        $this->twig->display($name . '.twig', $this->context);
    }

    public function context_merge(array $context) {
        $this->context = array_merge($this->context, $context);
    }

}
